<?php
/*
Plugin Name: Left Box
Plugin URI: 
Version: v1.0
Author: <a href="http://huynhuan.wordpress.com">HuanHH</a>
Description: Power by Cao Dang Nghe Long An.
*/
?>
<?php 
class LeftBox extends WP_Widget {

	function LeftBox() {
		$widget_ops = array('classname' => 'left_box', 'description' => 'Left Box' );
		$control_ops = array ('width' => '200', 'height' => '400');
		$this->WP_Widget('left_box', 'Left Box', $widget_ops, $control_ops);
	}
	
	function widget($args, $instance) {
		extract($args);
		extract($instance);
		?>
		
		<div id="<?php print $has_bg_title ? "box" : "box_nocolor"?>">
			<div class="top">
				<div class="title"><?php print $title; ?></div>
			</div>
			<div class="center">
				<?php if (!empty($content)) : ?>
					<?php echo $content; ?>
				<?php endif; ?>
			</div>
			<div class="bot"></div>
		</div>
		<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$title = $new_instance['title'];
		$content = $new_instance['content'];
		$has_bg_title = $new_instance['has_bg_title'] ? 1 : 0;
		$instance = compact('title', 'content', 'has_bg_title');
		return $instance;
	}

	function form($instance) {
		$defaults=array(
			'title' => __('Left Box', 'cdnla'),
			'content' => '',
			'has_bg_title' => 1
		);
		
		$options = wp_parse_args($instance, $defaults);
		extract($options);

		?>

		<div>
			<div>Title:</div>
			<div><input  id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></div>
			<div>Content:</div>
			<div><textarea  id="<?php echo $this->get_field_id('content'); ?>" style="width: 100%;" rows="7" name="<?php echo $this->get_field_name('content'); ?>"><?php echo attribute_escape($content); ?></textarea></div>
			<div><label><input  id="<?php echo $this->get_field_id('has_bg_title'); ?>" name="<?php echo $this->get_field_name('has_bg_title'); ?>" type="checkbox" <?php echo ($has_bg_title==1) ? "checked='checked'" : ""?> /> Has background title</label></div>
		</div>

		<?php
	}
}

if (class_exists("LeftBox")) {
	$left_box = new LeftBox();
}

function register_left_box() {
	register_widget('LeftBox');
}
add_action('widgets_init', 'register_left_box');

?>
